﻿@model asMeishi.web.Models.food
@using asMeishi.web.Models
@{

    Layout = null;

    ViewBag.Title = "p_items_detail";
    var impus = ViewBag.impressUser;
}
   <link href="@Url.Content("~/Content/css/public.css")" rel="stylesheet" type="text/css" />
   <link href="@Url.Content("~/Content/css/main.css")" rel="stylesheet" type="text/css" />
   <script src="@Url.Content("~/Scripts/jquery-1.4.1.min.js")" type="text/javascript"></script>
   <script src="@Url.Content("~/content/script/publicScript.js")" type="text/javascript"></script>

<div class="itemDetial">
            <H2 class="title">@Model.name</H2>
            <div>推荐人:<A href="">111</A><span>@Model.datatime</span></div>
            <div>介绍:@Model.intro</div>
            <div>图片:@Model.picUrls</div>
            <div>推荐次数:@Model.recommendCount</div>
            <div>点评数:@Model.commentsCount</div>


            <form class="impressForm" id="impressForm">
                <input type="text" id="impressContent" name="content"/>
                <button onclick="addItemImpress()">提交</button>
                <input type="hidden" id="itemId" name="itemId" value="@Model.Id" />
                <input type="hidden" id="loginUserId" value="@userC.loginUser.Id" />
                <input type="hidden" id="loginUserName" value="@userC.loginUser.name" />
            </form>

            <div class="impressList" id="itemImpressList" onclick="actionItemImpress(event)">
                @foreach (var impu in impus)
                {
                    impression imp = impu[0];
                    user user = impu[1];
                    <div class="impress">
                        <span class="datetime">@imp.datetime.ToLongDateString()</span>
                        @if (powerCheck.recordEditDel(imp.userId.ToString(), userC.loginUser)) {                  
                            <button class="delBtn" targetId="@imp.Id.ToString()">del</button>
                        }
                        <a href="@imp.userId" class="authorLink">@@@user.name</a>说:<div class="content">@imp.content</div> 
                        

                    </div>
                }
            </div>
</div>
<script>

    function actionItemImpress(evt) {
        var el = $.event.fix(event).target;
        if (el.className == ("delBtn")) {
            alert(el.getAttribute("targetId"))
            $.get("/item/delImpression/" + $("#itemId").attr("value"), { impressId:el.getAttribute("targetId")}, function (str) {
                alert(str.result)
            })
        }
    }
    function addItemImpress() {
        var _content = document.getElementById("content").value;
        if(_content==""){alert("不能为空");return;}

        $.post("/item/addImpression/" + $("#itemId").attr("value"), $("#impressForm").serialize(), function (result) {
                    inserImpress(result)
                });
    }
    function inserImpress(json) {
        json = eval(json)
        alert(json.content)
        if (json.result == "ok") {
            $("#itemImpressList").prepend('<div class="impress"><span class="datetime">' + (new Date()).pattern("yyyy-MM-dd") + '</span><button class="delBtn" targetId="' + json.content + '">del</button><a href="' + $("#loginUserId").val() + '" class="authorLink">' + $("#loginUserName").val() + '</a><div class="content">' + $("#impressContent").val() + '</div></div>')
        }
    }
</script>